﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:wfControls="clr-namespace:WhiteFlow.Wpf.Controls.Common;assembly=WhiteFlow.Wpf.Controls"
                    xmlns:controls="clr-namespace:WhiteFlow.DevTrackingTool.UI.Controls"
                    xmlns:converters="clr-namespace:WhiteFlow.DevTrackingTool.UI.Converters">
    
    <Style TargetType="{x:Type controls:TimePicker}">
        <Style.Resources>
            <converters:TimeSpanConverter x:Key="TimeSpanConverter" />
        </Style.Resources>
        
        <Setter Property="BorderBrush" Value="DarkGray" />
        <Setter Property="Foreground" Value="Black" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="PickerButtonsStyle" Value="{StaticResource ResourceKey=TimePickerButtonStyle}" />
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:TimePicker}">
                    <Border FocusManager.FocusedElement="{Binding ElementName=PART_BtnOpenHoursPopup}"
                            Background="{TemplateBinding Background}">
                        <DockPanel LastChildFill="True">
                            <DockPanel Name="DisplayedSection" 
                                       DockPanel.Dock="Top"
                                       LastChildFill="True"
                                       Panel.ZIndex="1">
                                <ToggleButton Name="PART_BtnOpenHoursPopup"
                                              DockPanel.Dock="Right"
                                              ToolTip="Select Time">
                                    <ToggleButton.Template>
                                        <ControlTemplate TargetType="{x:Type ToggleButton}">
                                            <Border VerticalAlignment="Center"
                                                    Background="{StaticResource ResourceKey=ContentsBgBrush}"
                                                    BorderThickness="0,1,1,1"
                                                    BorderBrush="{Binding Path=BorderBrush, ElementName=PART_TbSelectedTime}"
                                                    CornerRadius="0,3,3,0"
                                                    Cursor="Hand"
                                                    Padding="2">
                                                <wfControls:Bitmap Source="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Icons/TimePicker/clock_16x16.png" />
                                            </Border>
                                        </ControlTemplate>
                                    </ToggleButton.Template>
                                </ToggleButton>

                                <TextBox Name="PART_TbSelectedTime"
                                         MinWidth="50" 
                                         IsReadOnly="True"
                                         Padding="0,-2,0,0"
                                         Background="White"
                                         VerticalAlignment="Center"
                                         VerticalContentAlignment="Center"
                                         BorderBrush="{TemplateBinding BorderBrush}"
                                         FontSize="{TemplateBinding FontSize}"
                                         Height="{Binding Path=ActualHeight, ElementName=PART_BtnOpenHoursPopup}"
                                         Text="{Binding Path=SelectedTime, Converter={StaticResource ResourceKey=TimeSpanConverter}, Mode=OneWay, RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                            </DockPanel>

                            <Popup Name="PART_PopupHours"
                                   AllowsTransparency="True"
                                   PlacementTarget="{Binding ElementName=DisplayedSection}"
                                   Placement="Bottom"
                                   Panel.ZIndex="2"
                                   StaysOpen="False"
                                   PopupAnimation="Fade">
                                <Border Name="PopupBorder"
                                        Background="White" 
                                        CornerRadius="0,0,4,4"
                                        Panel.ZIndex="200"
                                        BorderBrush="DarkGray"
                                        BorderThickness="1">
                                    <DockPanel LastChildFill="True">
                                        <Border DockPanel.Dock="Top"
                                                CornerRadius="0"
                                                Padding="3,3,3,12">
                                            <Border.Background>
                                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                    <GradientStop Offset="0.0" Color="{StaticResource ResourceKey=ContentsBgColor}" />
                                                    <GradientStop Offset="0.8" Color="{StaticResource ResourceKey=ContentsBgColor}" />
                                                    <GradientStop Offset="1" Color="Transparent" />
                                                </LinearGradientBrush>
                                            </Border.Background>

                                            <TextBlock Name="PickerSelectionModeName" 
                                                       Text="Hours"
                                                       HorizontalAlignment="Center"
                                                       Foreground="White"
                                                       FontSize="16"
                                                       FontFamily="/WhiteFlow.DevTrackingTool.UI;Component/Resources/Fonts/#BIRTH OF A HERO" />
                                        </Border>

                                        <Grid Margin="3">
                                            <Grid Name="PART_MinutesGrid"
                                                  Background="White"
                                                  ShowGridLines="False"
                                                  Panel.ZIndex="1">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="25*" />
                                                    <ColumnDefinition Width="25*" />
                                                    <ColumnDefinition Width="25*" />
                                                    <ColumnDefinition Width="25*" />
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="34*" />
                                                    <RowDefinition Height="33*" />
                                                    <RowDefinition Height="34*" />
                                                </Grid.RowDefinitions>
                                            </Grid>

                                            <Grid Name="PART_HoursGrid"
                                                  Background="White"
                                                  ShowGridLines="False"
                                                  Panel.ZIndex="2">
                                                <Grid.ColumnDefinitions>
                                                    <ColumnDefinition Width="20*" />
                                                    <ColumnDefinition Width="20*" />
                                                    <ColumnDefinition Width="20*" />
                                                    <ColumnDefinition Width="20*" />
                                                    <ColumnDefinition Width="20*" />
                                                </Grid.ColumnDefinitions>
                                                <Grid.RowDefinitions>
                                                    <RowDefinition Height="20*" />
                                                    <RowDefinition Height="20*" />
                                                    <RowDefinition Height="20*" />
                                                    <RowDefinition Height="20*" />
                                                    <RowDefinition Height="20*" />
                                                </Grid.RowDefinitions>
                                            </Grid>
                                        </Grid>
                                    </DockPanel>
                                </Border>
                            </Popup>
                        </DockPanel>
                    </Border>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMinutesSelectionActive" Value="True">
                            <Setter TargetName="PickerSelectionModeName" Property="TextBlock.Text" Value="Minutes" />
                            <Setter TargetName="PART_HoursGrid" Property="Panel.ZIndex" Value="1" />
                            <Setter TargetName="PART_MinutesGrid" Property="Panel.ZIndex" Value="2" />
                        </Trigger>
                        <Trigger Property="BorderBrush" Value="Transparent">
                            <Setter TargetName="PopupBorder" Property="BorderBrush" Value="DarkGray" />
                        </Trigger>
                        <Trigger SourceName="PART_BtnOpenHoursPopup" Property="IsChecked" Value="True">
                            <Setter TargetName="PART_PopupHours" Property="IsOpen" Value="True" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>